/* GUI CONVERTED from rcabssup.p (converter v1.76) Wed Mar 20 09:09:12 2002 */
/* rcabssup.p - PROGRAM TO MAINTAIN abss_det FOR SEQUENCE SCHEDULES           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.10 $                                                           */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 9.1           CREATED: 05/24/99   BY: *N003* Patrick Rowan       */
/* REVISION: 9.1     LAST MODIFIED: 01/14/00   BY: *N076* Dan Herman          */
/* REVISION: 9.1     LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane    */
/* REVISION: 9.1     LAST MODIFIED: 05/12/00   BY: *N09X* Antony Babu         */
/* REVISION: 9.1     LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown          */
/* REVISION: 9.1     LAST MODIFIED: 08/18/00   BY: *N0MC* Annasaheb Rahane    */
/* Revision: 1.9          BY: Jean Miller       DATE: 03/22/01  ECO: *P008*   */
/* $Revision: 1.10 $      BY: Jean Miller       DATE: 03/20/02  ECO: *N1CL*   */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*!
 ----------------------------------------------------------------------------
 DESCRIPTION: This program manages a pop-up window (downframe) with subsequent
              pop-up windows to maintain sequence detail records.  This program
              is used when building shipper manually in the Shipper Work-
              Bench.

 Notes:
 ============================================================================
 !*/

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input parameter in_abs_id like abs_id no-undo.
define input parameter in_shipfrom like abs_shipfrom no-undo.
define input parameter maintenance like mfc_logical no-undo.

define new shared variable shipfrom like abs_shipfrom no-undo.
define new shared variable shipto like abs_shipto no-undo.
define new shared variable part like pt_part no-undo.
define new shared variable absid like abs_id no-undo.
define new shared variable cust_job like rcsd_cust_job no-undo.
define new shared variable cust_seq like rcsd_cust_seq no-undo.
define new shared variable cust_ref like rcsd_cust_ref no-undo.
define new shared variable sched_date like rcsd_date no-undo.
define new shared variable sched_time like rcsd_time no-undo.
define new shared variable prog_mode as integer no-undo.

define variable dock like rcsd_dock no-undo.
define variable line_feed like rcsd_line_feed no-undo.
define variable frametitle as character no-undo.
define variable updateframetitle as character no-undo.
define variable frametitle2 as character no-undo.
define variable frametitle3 as character no-undo.
define variable total_seq_qty like abss_qty no-undo.
define variable abs_recid as recid.
define variable abss_recid as recid.
define variable curr_abss_recid as recid.
define variable del-yn like mfc_logical no-undo.

define variable ADD_MODE as integer no-undo initial 1.
define variable DEL_MODE as integer no-undo initial 2.
define variable INQ_MODE as integer no-undo initial 3.

/* FRAME C: MULTI-LINE DOWN FRAME */
FORM /*GUI*/ 
   abss_date
   abss_time
   abss_cust_job
   abss_cust_seq
with down frame c overlay column 3 row 8
title color normal frametitle THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

/* FRAME D: UPDATE FRAME */
FORM /*GUI*/ 
   cust_job            colon 31
   cust_seq            colon 31
   cust_ref            colon 31
   dock                colon 31
   line_feed           colon 31
   sched_date          colon 31
   sched_time          colon 50
   skip (1)
   rcsd_discr_qty      colon 31
   pt_um               colon 50
   rcsd_status         colon 31
   rcsd_cust_build_date   colon 31
with down frame d overlay column 3 row 8 side-labels
width 70 title color normal updateframetitle THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame d:handle).

/* TRIGGER */
on leave of cust_job in frame d do:

   /* MAKE cust_job AVAILABLE FOR F2-HELP ON cust_seq */
   cust_job = input frame d cust_job.

        
   do on error undo, leave:
   run q-leave in global-drop-down-utilities.
   end.
   run q-set-window-recid in global-drop-down-utilities.
   if return-value = "error" then return no-apply.   

end.

/* INITIALIZATION */
for first abs_mstr where
          abs_id          = in_abs_id and
          abs_shipfrom    = in_shipfrom
no-lock: end.

abs_recid = recid(abs_mstr).

for first so_mstr
where so_nbr = abs_order
no-lock: end.

for first sod_det
where sod_nbr = abs_order and
      sod_line = integer(abs_line)
no-lock:
end.

/* COMPUTE INITIAL TOTAL FOR LINE */
assign
   total_seq_qty = 0.

for each abss_det where
         abss_abs_id     = abs_id        and
         abss_shipfrom   = abs_shipfrom
no-lock:
   total_seq_qty = total_seq_qty + abss_qty.
end.

/* LEAVE IF NO SEQUENCES FOUND FOR THIS ORDER */
for first rcs_mstr
where rcs_shipfrom    = so_site   and
      rcs_shipto      = so_ship   and
      rcs_active
no-lock: end.

if available (rcs_mstr) then do:
   for first rcsd_det
   where rcsd_rlse_id    = rcs_rlse_id and
         rcsd_order      = so_nbr and
         rcsd_line       = sod_line
   no-lock: end.

   if not available (rcsd_det) then
      leave.
end.  /* if available (rcs_mstr) */
else
   leave.

assign
   frametitle  = getFrameTitle("DISPLAY_SEQUENCES",24) + "- " +
                 getTermLabel("ORDER_QUANTITY",20) + ": " +
                 string(abs_qty) + " " +
                 substring(abs__qad02,1,2) + " "

   frametitle2 = getFrameTitle("DELETE_SEQUENCES",23) + "- " +
                 getTermLabel("ORDER_QUANTITY",20) + ": " +
                 string(abs_qty) + " " +
                 substring(abs__qad02,1,2) + " "

   frametitle3 = getFrameTitle("DISPLAY_SEQUENCE_DETAIL",32) + "- " +
                 getTermLabel("ORDER_QUANTITY",20) + ": " +
                 string(abs_qty) + " " +
                 substring(abs__qad02,1,2) + " "
   shipfrom    = so_site
   shipto      = so_ship
   part        = sod_part
   absid       = abs_id
   prog_mode   = INQ_MODE.

loop1:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

      if can-find (first abss_det where
         abss_abs_id     = abs_id        and
         abss_shipfrom   = abs_shipfrom)
      then do with frame c:

         /*TOTAL QUANTITY ENTERED */
         {pxmsg.i &MSGNUM=2971 &ERRORLEVEL=1 &MSGARG1=total_seq_qty}

         {swindar.i
            &searchkey    = abs_id
            &other-search = "and abs_shipfrom = abss_shipfrom"
            &detfile      = abss_det
            &detkey       = abss_abs_id
            &detlink      = abss_part
            &mstrfile     = pt_mstr
            &mstrkey      = pt_part
            &scroll-field = abss_cust_job
            &framename    = "c"
            &framesize    = 6
            &display1     = abss_date
            &display2     = abss_time
            &display3     = abss_cust_job
            &display4     = abss_cust_seq
            &exitlabel    = loop1
            &exit-flag    = false
            &record-id    = abss_recid
            &statusline   = stline[10]
            &go-on        = "go-on (F5 Ctrl-D)"
            &postchoosehook = "~
                       if keyfunction(lastkey) = 'INSERT-MODE' then do:
                          curr_abss_recid = sw_frame_recid[1].
                          hide frame c.
                          prog_mode   = ADD_MODE.
                          run add_mode
                             (input abs_recid,
                              input recid(rcs_mstr),
                              input recid(sod_det),
                              output abss_recid,
                              input-output total_seq_qty).
                          sw_recid =  if abss_recid <> ? then
                                         abss_recid
                                      else
                                         curr_abss_recid.
                          next sw-main-loop.
                       end.
                       if (lastkey = keycode('ctrl-d') or
                           lastkey = keycode('F5')) and
                          sw_frame_recid[frame-line(c)] <> ?
                       then do:
                          assign
                             abss_recid = sw_frame_recid[frame-line(c)].
                             curr_abss_recid = if frame-line(c) = 1
                                                then sw_frame_recid[2]
                                                else sw_frame_recid
                                                        [frame-line(c) - 1].
                          hide frame c.
                          assign
                            updateframetitle = frametitle2
                            prog_mode   = DEL_MODE.
                          run del_mode
                             (input abs_recid,
                              input abss_recid,
                              output del-yn,
                              input-output total_seq_qty).

                          if del-yn then
                             sw_recid = curr_abss_recid.
                          else
                             sw_recid = abss_recid.
                          next sw-main-loop.
                       end."
         }

      end. /* if can-find first abss_det */

      else do:

         /*IF NO ENTRIES THEN POP-UP ADD FRAME */
         hide frame c.
         prog_mode   = ADD_MODE.
         run add_mode
            (input abs_recid,
             input recid(rcs_mstr),
             input recid(sod_det),
             output abss_recid,
             input-output total_seq_qty).

         for first abss_det
         where abss_abs_id     = abs_id    and
               abss_shipfrom   = abs_shipfrom
         no-lock: end.

         if available (abss_det) then
            next loop1.
         else
            leave loop1.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      /*WHEN ENTER HIT, DISPLAY SEQUENCE DETAIL */
      hide frame c.
      assign
         updateframetitle = frametitle3
         prog_mode   = INQ_MODE.

      run inq_mode
         (input abs_recid,
          input recid(rcs_mstr),
          input recid(sod_det),
          input-output abss_recid,
          input-output total_seq_qty).

      if keyfunction(lastkey) = "end-error"  then do:
         for first abss_det
         where abss_abs_id     = abs_id    and
               abss_shipfrom   = abs_shipfrom
         no-lock: end.
         if available (abss_det) then
            next loop1.
      end.
      else
         leave loop1.

   end. /* do */

   hide frame c.
   hide frame d.
   clear frame d.

end. /* loop1 */

if total_seq_qty <> abs_qty then do:
   /*WARNING: TOTAL SEQUENCE QTY <> LINE QTY */
   {pxmsg.i &MSGNUM=2979 &ERRORLEVEL=2}
end.


PROCEDURE inq_mode:
/*--------------------------------------------------------------------
  Purpose:
  Parameters:
  Notes:
---------------------------------------------------------------------*/
   define input parameter abs_recid as recid no-undo.
   define input parameter rcs_recid as recid no-undo.
   define input parameter sod_recid as recid no-undo.
   define input-output parameter abss_recid as recid no-undo.
   define input-output parameter total_seq_qty like abss_qty no-undo.

   for first abss_det
   where recid(abss_det) = abss_recid
   no-lock: end.

   if available (abss_det) then do:
      for first rcsd_det
      where rcsd_shipfrom   = abss_shipfrom  and
            rcsd_shipto     = abss_shipto    and
            rcsd_rlse_id    = abss_rlse_id   and
            rcsd_cust_job   = abss_cust_job  and
            rcsd_cust_seq   = abss_cust_seq  and
            rcsd_part       = abss_part      and
            rcsd_date       = abss_date      and
            rcsd_time       = abss_time      and
            rcsd_cust_ref   = abss_cust_ref  and
            rcsd_dock       = abss_dock      and
            rcsd_line_feed  = abss_line_feed
      no-lock: end.

      if available (rcsd_det) then
         for first pt_mstr
         where pt_part = rcsd_part
         no-lock: end.

      display
         abss_cust_job   @ cust_job
         abss_cust_seq   @ cust_seq
         abss_cust_ref   @ cust_ref
         abss_dock       @ dock
         abss_line_feed  @ line_feed
         abss_date       @ sched_date
         abss_time       @ sched_time
         rcsd_discr_qty          when (available rcsd_det)
         pt_um                   when (available pt_mstr)
         rcsd_status             when (available rcsd_det)
         rcsd_cust_build_date    when (available rcsd_det)
      with frame d.

      abss_recid = recid(abss_det).

   end.  /* if available (abss_det) */

   inq-loop:
   repeat on error undo, retry with frame d:

      for first rcs_mstr
      where recid(rcs_mstr) = rcs_recid
      no-lock: end.

      for first abs_mstr
      where recid(abs_mstr) = abs_recid
      no-lock: end.

      for first sod_det
      where recid(sod_det) = sod_recid
      no-lock: end.

      /*TOTAL QUANTITY ENTERED */
      {pxmsg.i &MSGNUM=2971 &ERRORLEVEL=1 &MSGARG1=total_seq_qty}

      /*Handle the branching and parameters for cust_job and cust_seq*/
      if prog_mode = ADD_MODE then do:
         {gprun.i ""gpbranch.p""
            "(input 'rclu010.p', input '')"}
/*GUI*/ if global-beam-me-up then undo, leave.

         {gprun.i ""gpbranch.p""
            "(input 'rclu011.p', input '')"}
/*GUI*/ if global-beam-me-up then undo, leave.

         {gpbrparm.i &browse=rclu010.p &parm=c-brparm1 &val=shipfrom}
         {gpbrparm.i &browse=rclu011.p &parm=c-brparm1 &val=shipfrom}
         {gpbrparm.i &browse=rclu010.p &parm=c-brparm2 &val=shipto}
         {gpbrparm.i &browse=rclu011.p &parm=c-brparm2 &val=shipto}
         {gpbrparm.i &browse=rclu010.p &parm=c-brparm3 &val=part}
         {gpbrparm.i &browse=rclu011.p &parm=c-brparm3 &val=part}
      end.
      else if prog_mode = INQ_MODE then do:
         {gprun.i ""gpbranch.p""
            "(input 'rclu010.p', input 'rclu020.p')"}
/*GUI*/ if global-beam-me-up then undo, leave.

         {gprun.i ""gpbranch.p""
            "(input 'rclu011.p', input 'rclu021.p')"}
/*GUI*/ if global-beam-me-up then undo, leave.

         {gpbrparm.i &browse=rclu020.p &parm=c-brparm1 &val=shipfrom}
         {gpbrparm.i &browse=rclu021.p &parm=c-brparm1 &val=shipfrom}
         {gpbrparm.i &browse=rclu020.p &parm=c-brparm2 &val=shipto}
         {gpbrparm.i &browse=rclu021.p &parm=c-brparm2 &val=shipto}
         {gpbrparm.i &browse=rclu020.p &parm=c-brparm3 &val=part}
         {gpbrparm.i &browse=rclu021.p &parm=c-brparm3 &val=part}
         {gpbrparm.i &browse=rclu020.p &parm=c-brparm4 &val=absid}
         {gpbrparm.i &browse=rclu021.p &parm=c-brparm4 &val=absid}
      end.

      set
         cust_job
         cust_seq
         cust_ref
         dock
         line_feed
         sched_date
         sched_time
      with frame d editing:

         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp15.i abss_det abss_index1
            "abss_abs_id = abs_id and abss_shipfrom = abs_shipfrom"
            abss_cust_job "input frame d cust_job"
            abss_cust_seq "input frame d cust_seq"
            abss_cust_ref "input frame d cust_ref"
            abss_dock "input frame d dock"
            abss_line_feed "input frame d line_feed"
            abss_date "input frame d sched_date"
            abss_time "input frame d sched_time"}

         if recno <> ? then do:
            for first rcsd_det
            where rcsd_shipfrom   = abss_shipfrom  and
                  rcsd_shipto     = abss_shipto    and
                  rcsd_rlse_id    = abss_rlse_id   and
                  rcsd_cust_job   = abss_cust_job  and
                  rcsd_cust_seq   = abss_cust_seq  and
                  rcsd_part       = abss_part      and
                  rcsd_date       = abss_date      and
                  rcsd_time       = abss_time      and
                  rcsd_dock       = abss_dock      and
                  rcsd_line_feed  = abss_line_feed and
                  rcsd_cust_ref   = abss_cust_ref
            no-lock: end.

            if available (rcsd_det) then
               for first pt_mstr
               where pt_part = rcsd_part
               no-lock: end.

            display
               abss_cust_job   @ cust_job
               abss_cust_seq   @ cust_seq
               abss_cust_ref   @ cust_ref
               abss_dock       @ dock
               abss_line_feed  @ line_feed
               abss_date       @ sched_date
               abss_time       @ sched_time
               rcsd_discr_qty      when (available rcsd_det)
               pt_um               when (available pt_mstr)
               rcsd_status         when (available rcsd_det)
               rcsd_cust_build_date
               when (available rcsd_det)
            with frame d.

            abss_recid = recid(abss_det).

         end. /* if recno */

      end. /* prompt-for abss_cust_job */

      /* LOOK-UP */
      for first abss_det
      where abss_abs_id     = abs_id        and
            abss_shipfrom   = abs_shipfrom  and
            abss_shipto     = rcs_shipto    and
            abss_rlse_id    = rcs_rlse_id   and
            abss_part       = abs_item      and
            abss_cust_job   = input frame d cust_job      and
            abss_cust_seq   = input frame d cust_seq      and
            abss_cust_ref   = input frame d cust_ref      and
            abss_dock       = input frame d dock          and
            abss_line_feed  = input frame d line_feed     and
            abss_date       = input frame d sched_date    and
            abss_time       = input frame d sched_time
      no-lock: end.

      if available (abss_det) then do:
         for first rcsd_det
         where rcsd_shipfrom   = abss_shipfrom  and
               rcsd_shipto     = abss_shipto    and
               rcsd_rlse_id    = abss_rlse_id   and
               rcsd_cust_job   = abss_cust_job  and
               rcsd_cust_seq   = abss_cust_seq  and
               rcsd_part       = abss_part      and
               rcsd_date       = abss_date      and
               rcsd_time       = abss_time      and
               rcsd_dock       = abss_dock      and
               rcsd_line_feed  = abss_line_feed and
               rcsd_cust_ref   = abss_cust_ref
         no-lock: end.

         if available (rcsd_det) then
            for first pt_mstr
            where pt_part = rcsd_part
            no-lock: end.

         display
            abss_cust_job   @ cust_job
            abss_cust_seq   @ cust_seq
            abss_cust_ref   @ cust_ref
            abss_date       @ sched_date
            abss_time       @ sched_time
            abss_dock       @ dock
            abss_line_feed  @ line_feed
            rcsd_discr_qty      when (available rcsd_det)
            pt_um               when (available pt_mstr)
            rcsd_status         when (available rcsd_det)
            rcsd_cust_build_date
            when (available rcsd_det)
         with frame d.

         abss_recid  = recid(abss_det).

      end.
      else do:
         {pxmsg.i &MSGNUM=2914 &ERRORLEVEL=3} /* SEQUENCE NOT FOUND */
         undo, retry.
      end.

   end.  /* END OF inq-loop */

   clear frame d.
   hide frame d.

END PROCEDURE. /* inq_mode */

PROCEDURE add_mode:
/*--------------------------------------------------------------------
  Purpose:
  Parameters:
  Notes:
---------------------------------------------------------------------*/
   define input parameter abs_recid as recid no-undo.
   define input parameter rcs_recid as recid no-undo.
   define input parameter sod_recid as recid no-undo.
   define output parameter abss_recid as recid no-undo.
   define input-output parameter total_seq_qty like abss_qty no-undo.

   {gprun.i ""rcabssad.p""
      "(input abs_recid,
        input rcs_recid,
        input sod_recid,
        output abss_recid,
        input-output total_seq_qty)"}
/*GUI*/ if global-beam-me-up then undo, leave.


END PROCEDURE. /* add_mode */

PROCEDURE del_mode:
/*--------------------------------------------------------------------
  Purpose:
  Parameters:
  Notes:
---------------------------------------------------------------------*/
   define input parameter in_abs_recid as recid no-undo.
   define input parameter in_abss_recid as recid no-undo.
   define output parameter del-yn like mfc_logical no-undo.
   define input-output parameter total_seq_qty like abss_qty no-undo.

   del-loop:
   do transaction on endkey undo, leave:

      for first abss_det
      where recid(abss_det) = in_abss_recid
      exclusive-lock: end.

      if available (abss_det) then do:

         for first rcsd_det
         where rcsd_shipfrom   = abss_shipfrom and
               rcsd_shipto     = abss_shipto   and
               rcsd_rlse_id    = abss_rlse_id  and
               rcsd_cust_job   = abss_cust_job and
               rcsd_cust_seq   = abss_cust_seq and
               rcsd_part       = abss_part     and
               rcsd_date       = abss_date     and
               rcsd_time       = abss_time     and
               rcsd_cust_ref   = abss_cust_ref and
               rcsd_dock       = abss_dock     and
               rcsd_line_feed  = abss_line_feed:
         end.

         if available (rcsd_det) then do:

            for first pt_mstr
            where pt_part   = abss_part
            no-lock: end.

            display
               abss_cust_job    @ cust_job
               abss_cust_seq    @ cust_seq
               abss_cust_ref    @ cust_ref
               abss_dock        @ dock
               abss_line_feed   @ line_feed
               abss_date        @ sched_date
               abss_time        @ sched_time
               rcsd_discr_qty
               pt_um       when (available pt_mstr)
               rcsd_status
               rcsd_cust_build_date
            with frame d.

         end.  /* if available (rcsd_det) */

         del-yn = no.

         /* DO YOU WANT TO DELETE THE RECORDS ? */
         {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn
               &CONFIRM-TYPE='LOGICAL'}
         if del-yn = no then
            undo del-loop, leave del-loop.

         if del-yn then do:
            total_seq_qty = total_seq_qty - abss_qty.

            {gprun.i ""rcabssdl.p""
               "(input abs_recid,
                 input in_abss_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            if available (rcsd_det) then
               clear frame d.

         end. /* if del-yn */

      end.  /* if available (abss_det) */

   end.  /* END OF del-loop */

   clear frame d.
   hide frame d.

END PROCEDURE. /* del_mode */
